<template>
	<view class="activityOrderConfirm" :style="[{paddingTop:statusBar+ 'px'}]">
		<view class="status" :style="[{height:statusBar+ 'px'}]" ></view>
		<view class="navigation" :style="[{top:(statusBar-2)+ 'px'}]">
			<image src="/static/images/back.png" class="back" @click="back()" mode=""></image>
			<view class="navigation-title" v-if="isExReturn" >确认申请全额返</view>
			<view class="navigation-title" v-else >确认发货</view>
		</view>
		<view class="navigation-position"></view>
		<view class="activity-order-confirm-content">
			<order-address-entrance-com></order-address-entrance-com>
			<view class="order-good-info">
				<view class="order-good-info-title">商品清单</view>
				<view class="order-good">
					<view class="order-good-icon-box">
						<image :src="orderDetail.product_cover" mode=""></image>
					</view>
					<view class="order-good-right">
						<view class="order-good-title">{{ orderDetail.product_title }}</view>
						<view class="gold-goods-price-area">
							<view>
								<text>权益价</text>
								<text>￥{{ orderDetail.pay_net_price }}</text>
							</view>
							<view>
								<text>抢购金</text>
								<text>￥{{ orderDetail.pay_cash_price }}</text>
							</view>
						</view>
						<view class="order-good-price">
							<text>￥</text>
							<text>{{ orderDetail.record_all_price }}</text>
						</view>
					</view>	
				</view>	
			</view>
		</view>
		<view class="confirm-btn" @click="goldProductSplitting()" v-if="isExReturn">确认申请全额返</view>	
		<view class="confirm-btn" @click="goldProductTaking()" v-else>确认发货</view>	
		
	</view>
</template>

<script>
	/* function getRequestParams() {
			let url = location.href;
			let requestParams = {};
			if (url.indexOf('?') !== -1) {
				let str = url.substr(url.indexOf('?') + 1);
				let strs = str.split('&');
				for (let i = 0; i < strs.length; i++) {
					requestParams[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1]);
				}
			}
			return requestParams;
	}
	let params = getRequestParams();
	let token = params['token'];
	let status_bar =  params['status_bar'];
	let source = 'wap'
	if(token!=undefined){
		uni.setStorage({
		    key: 'token',
		    data: token
		})
		source = 'app'
	}
	if(status_bar!=undefined){
		uni.setStorage({
		    key: 'status_bar',
		    data: status_bar
		})
	} */
	import store from "store"
	import {mapGetters,mapMutations,mapActions} from 'vuex'
	import OrderAddressEntranceCom from "components/order/confirm/OrderAddressEntranceCom"
	import { goldProductTaking,goldProductSplitting } from "api/goldstormApi.js"
	
	export default {
		store,
		components: {
			OrderAddressEntranceCom
		},
		computed:{
			...mapGetters([
				'user',
				'statusBar',
				'currentAddress'
			])
		},
		data:()=>({
			source:source,
			orderDetail:{},
			address_id:'',
			isExReturn:true
		}),
		methods:{
			...mapMutations([
				'setUser',
				'setStatusBar'
			]),
			back(){
				if(this.source == 'wap'){
					uni.navigateBack()
				}else{
					// window.flutter_inappwebview.callHandler('back_to_app', '')
					backToApp.postMessage('back');
				}
			},
			async goldProductTaking(){
				if (!this.currentAddress) {
					uni.showToast({
						title: '请选择收货地址'
					})
					return
				}
				let parms = {
					address:this.currentAddress.id,
					record:this.orderDetail.cid
				}
				
				uni.navigateTo({
					url:'/packs/pages/activity/activityPriceDifference?parms='+ encodeURIComponent(JSON.stringify(parms)) + '&price=' + this.orderDetail.pay_cash_price
				})
				
				// const response = await goldProductTaking(parms)
				// if(response.errors){
				// 	return 
				// }else{
				// 	if(!response.message){
				// 		uni.showModal({
				// 			title:'提示',
				// 			content:'发货订单已提交，请耐心等待发货！',
				// 			confirmText:'知道了',
				// 			showCancel:false,
				// 			success: function (res) {
				// 				if (res.confirm) {
				// 					var pages= getCurrentPages()
				// 					var prevPage = pages[pages.length-2]
				// 					prevPage.$vm.backEventSelling()
				// 					uni.navigateBack({})
				// 				}
				// 			}
				// 		})
				// 	}else{
				// 		uni.showModal({
				// 			title:'提示',
				// 			content:Object.values(response.errors)[0][0],
				// 			confirmText:'知道了',
				// 			confirmColor:'#FF6011',
				// 			showCancel:false
				// 		})
				// 	}
				// }
			},
			goldProductSplitting(){
				if (!this.currentAddress) {
					uni.showToast({
						title: '请选择收货地址'
					})
					return
				}
				let records = []
				records.push(this.orderDetail.id)
				let goldbeans = parseInt(this.orderDetail.record_beans)
				uni.redirectTo({
					url:'/packs/pages/activity/activitySellConfirm?records=' + encodeURIComponent(JSON.stringify(records)) + '&needGoldbeans=' + goldbeans + '&address_id=' + this.currentAddress.id + '&gold_record_id=' + this.orderDetail.id  +'&isExReturn=true' 
				})
			}
		},
		async onShow(){
			if(status_bar!=undefined){
				this.setStatusBar(status_bar)
			}
		},
		onLoad(options) {
			this.orderDetail = JSON.parse(decodeURIComponent(options.orderDetail))
			this.isExReturn = JSON.parse(options.isExReturn)
			
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background: #F6F6F6;
	}
	.status {
		width: 100%;
		position: fixed;
		top: 0;
		z-index: 99;
		background: #F6F6F6;
	}
	.navigation{
		width: 100%;
		height: 100rpx;
		background: #F6F6F6;
		display: flex;
		align-items: center;
		justify-content: center;
		position: fixed;
		left:0;
		top:0;
		z-index:999;
	}
	.navigation-position{
		width: 100%;
		height: 100rpx;
		background: rgba(0,0,0,0);
	}
	.back{
		display: block;
		width: 48rpx;
		height: 48rpx;
		position: absolute;
		top: 26rpx;
		left:32rpx;
	}
	.navigation-title{
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
	}
	.header{
		width: 690rpx;
		height:300rpx;
		border-radius: 10rpx;
		margin: 0 auto;
		background: rgb(253,134,84);
	}
	.header-title{
		padding:40rpx 0 20rpx 0;
		text-align: center;
		color: #333333;
		font-size: 28rpx;
	}
	.activity-order-confirm-content{
		padding: 20rpx;
	}
	.order-good-info{
		width: 100%;
		height:280rpx;
		border-radius: 20rpx;
		background: #ffffff;
	}
	.order-good-info-title{
		font-size: 28rpx;
		font-weight: 500;
		padding: 20rpx 0 20rpx 30rpx;
	}
	.order-good-icon-box{
		width: 170rpx;
		height: 170rpx;
		border-radius: 10rpx;
		margin-left: 20rpx;
		>image{
			display: block;
			width: 100%;
			height: 100%;
		}
	}
	.order-good{
		display: flex;
	}
	.order-good-right{
		margin-left: 15rpx;
	}
	.order-good-title{
		width: 480rpx;
		height: 40rpx;
		line-height: 40rpx;
		font-size: 28rpx;
		color:#333333;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		overflow: hidden;
		margin-top: 10rpx;
	}
	.gold-goods-price-area{
		display: flex;
		font-size: 26rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
		line-height: 34rpx;
		height: 32rpx;
		margin:8rpx 0 0 0rpx;
		>view{
			>text:nth-child(2){
				font-family: DINAlternate-Bold, DINAlternate;
				font-weight: bold;
			}
		}
		>view:nth-child(1){
			margin-right: 32rpx;
			color: #FF4924;
		}
	}
	.order-good-price{
		display: flex;
		margin-top: 20rpx;
		>text:nth-child(1){
			font-size: 20rpx;
			margin-top: 22rpx;
			color:#FF4924;
		}
		>text:nth-child(2){
			font-size: 40rpx;
			font-weight: 500;
			color:#FF4924;
		}
		>text:nth-child(4){
			font-size: 30rpx;
			font-weight: 400;
			color:#666666;
			margin-top: 8rpx;
			letter-spacing: 2rpx;
			margin-left: 50rpx;
		}
		>image{
			display: block;
			width: 68rpx;
			height: 28rpx;
			margin: 16rpx 0 0 12rpx;
		}
	}
	.confirm-btn{
		width: 600rpx;
		height: 80rpx;
		border-radius: 60rpx;
		color:#ffffff;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		background: #FF9500;
		margin: 60rpx auto;
		font-weight: 500;
		letter-spacing: 2rpx;
	}
</style>